use axum::Json;
use serde::{Deserialize, Serialize};
use crate::api::get_console::{get_console, Console};
use crate::db::db_insert::db_insert;

#[derive(Serialize, Deserialize, Debug)]
pub struct ConsoleList {
    pub consoles: Option<Vec<Console>>,
}
pub async fn _get_console() -> Json<ConsoleList> {
    if let Ok(consoles) = get_console().await {
        let json = ConsoleList {
            consoles: Some(consoles),
        };
        return Json(json);
    } else {
        let json = ConsoleList {
            consoles: None,
        };
        return Json(json);
    }
}
pub async fn _save_console(Json(payload): Json<Console>) {
    db_insert("host_id", &payload.id).await.unwrap();
}